Skip to content

feat: configure OpenAI-compatible model providers (on top of the audit) - #2

Merged
MattDHill merged 3 commits into
Start9-Community:masterfrom
jonbotx:provider-config
Nov 25, 2026
Merged

MattDHill merged 3 commits into
Start9-Community:masterfrom
jonbotx:provider-config

Conversation

@jonbotx

@jonbotx jonbotx commented Nov 24, 2026 •

Copy link
Copy Markdown

What this adds

OpenCode's own web app connects hosted providers under Settings → Providers — its catalog lists 334 (OpenRouter, Anthropic, OpenAI, LM Studio among them) — and answers out of the box on a free opencode model. What the packaged 2.4.1 build could not do without a shell is connect an OpenAI-compatible endpoint the catalog has no entry for: a self-hosted vLLM, LM Studio, or Ollama server on the LAN. This adds a Configure Model Providers action for exactly that.

For each provider the action writes an entry into OpenCode's own config (main/.config/opencode/opencode.json, on the main volume) and keeps the API key on the startos volume, handed to the server as an OPENCODE_KEY_<ID> environment variable and referenced from the config as {env:OPENCODE_KEY_<ID>} — so no secret is written to the config file. The config file is hot-reloaded by OpenCode, so a provider-only change needs no restart; a new or changed key restarts the daemon so the variable is picked up.

It is layered on top of chore/community-audit (#1), so it inherits the digest pin and the packageRepo move and adds only the feature:

  • startos/actions/configureProviders.ts — one repeatable provider list (id, name, base URL, optional masked key, models, default toggle)
  • startos/fileModels/opencode.json.ts — a tolerant JSONC model of OpenCode's own config (comments and trailing commas accepted, unknown keys preserved)
  • startos/fileModels/store.json.ts — adds providerKeys
  • startos/main.ts — injects each stored key as OPENCODE_KEY_<ID>, reactively
  • startos/utils.ts, startos/actions/index.ts, i18n in 5 locales, README / instructions / AGENTS

Bumps 2.4.1:0 → 2.4.1:1. No migration — the change is an added optional key.

Ownership

The action owns only the entries it writes — those carrying package: @opencode/ai/providers/openai-compatible. It prefills and rebuilds those, keeps every other providers entry verbatim, and touches model only when this save sets a Default or when it names a managed provider this save removes. A submitted ID that collides with an unmanaged entry is rejected before either file changes. A hand-written compatible entry's literal settings.apiKey is prefilled and moved into providerKeys on save.

Correcting the earlier provider claim

An earlier revision of this PR — and of #1's provider lines — claimed the served 2.4.1 UI had no provider screen. That was wrong: we had only driven the package through start-cli and inferred the UI from upstream rather than from the running app. The served bundle does carry Settings → Providers (/api/integration = 334 providers; /api/model shows the free default). The docs now say hosted providers connect in the app, and this action is for OpenAI-compatible endpoints the catalog cannot reach.

Verification

Adopted helix-white's proposal/2 (JSONC parsing via FileHelper.raw, ID-collision rejection, literal-key carry-over, doc cleanup) by cherry-pick, plus two small deltas: a Prettier paren in the prefill ternary, and one stale code comment reworded.

Installed the CI-built x86_64 package (2.4.1:1) on a StartOS 0.4.2 box, over data preserved from the released build, and drove the action through start-cli:

  • JSONC config. Seeded opencode.json with comments and trailing commas (a file plain JSON.parse rejects) plus one managed and one unmanaged provider. The action's prefill read it (get-input returned the managed entry with its literal key) and a save rewrote the file as JSON — the form opens.
  • ID collision. Submitting openrouter, an unmanaged entry, failed with Provider ID "openrouter" belongs to a provider configured outside this action. Choose another ID., and both opencode.json and store.json were byte-for-byte unchanged.
  • Literal key. A hand-written compatible entry with settings.apiKey: "sk-…" prefilled that literal; on save the config became {env:OPENCODE_KEY_LAB}, the literal moved into store.json → providerKeys, the unmanaged entry and a model of opencode/big-pickle were preserved, and the running daemon carried OPENCODE_KEY_LAB.
  • Earlier: adding/removing providers and keys, keyless providers, default-selection and its removal, and hand-edited keys the package does not own (theme, autoupdate) all behave as intended.
  • tsc --noEmit and Prettier are clean; both arches build in CI.

The packaged OpenCode 2.4.1 web interface has no provider screen, so there was
no way to point the service at a model without shelling into the container.

Add a Configure Model Providers action that writes provider entries into
OpenCode's own config on the main volume, and keeps each provider's API key on
the startos volume, passed to the server as OPENCODE_KEY_<ID>.
@MattDHill
MattDHill deleted the branch Start9-Community:chore/community-audit November 25, 2026 15:39
@MattDHill MattDHill closed this Nov 25, 2026
@MattDHill MattDHill reopened this Nov 25, 2026
@MattDHill
MattDHill changed the base branch from chore/community-audit to master November 25, 2026 15:39

@MattDHill MattDHill left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — #1 is merged (with a merge commit, so this PR's diff is now just the provider feature), and we're following your order: this one next, then #3.

Connecting a self-hosted endpoint without a shell is worth having. The upstream catalog has no entry that takes your own vLLM or Ollama URL on the LAN. The change needs these fixes first:

1. The served 2.4.1 web app does have a provider screen. We ran the pinned image (2.4.1@sha256:10e340e3…) and pulled the UI bundle opencode serve serves. Settings → Providers is in it, registered as one of the server tabs (providers, models, extensions, projects, workspaces) alongside the "Connect an integration" dialog. /api/integration lists 334 hosted providers, OpenRouter, Anthropic, OpenAI and LM Studio among them. OpenCode also works with no provider at all: its default opencode/big-pickle model needs no key, and we had the agent write a file into a project with nothing configured. What did you see when you looked for the screen? Your verification notes say you drove the package through start-cli only.

So the docs should say: hosted providers connect in Settings → Providers, and this action is for OpenAI-compatible endpoints the catalog can't reach. Please change these lines:

  • instructions step 4 ("Before OpenCode can answer anything it needs a model to use")
  • the instructions limitation "The web app in this version has no provider screen"
  • the README's "It is the only way to connect a model: the packaged OpenCode web interface has no provider screen of its own", and the same claim in its install section

2. Please don't reintroduce what #1 removed.

  • The README says "pinned to a released tag" again, but the Dockerfile pins the tag and digest.
  • "Nothing upstream is disabled or skipped" contradicts the disabled self-updater.
  • "A warning is shown before it runs" restates action metadata the OS already reports.
  • The instructions parenthetical "(enable an address there if none is enabled yet)" explains StartOS rather than this package.
  • In AGENTS.md: the "Working here" block is generic to every package, the port bullet is moot (it's one constant), and the image-pin bullet duplicates UPDATING.md. The packaging guide asks AGENTS.md for only what README and instructions can't say. New bullets for this feature are welcome in that form.

3. Have the action manage only the providers it creates. Each save rebuilds the whole providers map and model from the form, so it also overwrites entries the user or OpenCode wrote:

  • A provider added by hand without settings.baseURL (any catalog provider) prefills an empty Base URL, which is required, so the form can't be saved at all.
  • A key written directly into the config (settings.apiKey: "sk-…") prefills blank, since it isn't in providerKeys, and saving deletes it.
  • Saving with no Default ticked clears a model set to anything else.

Scoping the action to entries using @opencode/ai/providers/openai-compatible, and touching model only when it names one of them, closes all three.

4. Comments. Several new ones are paragraphs explaining the reasoning (opencode.json.ts, store.json.ts, main.ts, utils.ts, the action). Please cut each to the one fact the code can't show, or drop it; the reasoning belongs in the PR body. #1 did the same trim on the existing files.

Once this is revised we'll build and test it on a box. #3 can then be rebased onto it. We'll review its CA work separately.

Addresses the review on #2.

- The action now owns only the providers it wrote: the `opencode.json`
  entries carrying `package: @opencode/ai/providers/openai-compatible`.
  It prefills and rebuilds those, and copies every other entry — and a
  `model` that names none of them — through untouched. `model` is now
  changed only when a Default is set or when it names a managed provider
  this save removes, so saving with nothing ticked no longer clears a
  model set to something else.
- Docs: the served 2.4.1 web app does have Settings → Providers (the
  catalog lists 334 providers, and OpenCode ships a free default model).
  Restore the audit's step 4 and correct the "no provider screen" claims
  in `instructions.md` and `README.md`: hosted providers connect in the
  app, and this action is for OpenAI-compatible endpoints the catalog
  cannot reach.
- Restore claims #1 had already removed: the image is pinned by tag and
  digest; drop "nothing upstream is disabled or skipped" (the self-updater
  is off), the warning restatement, and the StartOS address parenthetical.
- Trim AGENTS.md to rules: drop the generic "Working here" block, the port
  bullet, and the image-pin bullet, and add the scoping rule for the action.
- Cut the new comments to one fact each.
@jonbotx

jonbotx commented Nov 25, 2026

Copy link
Copy Markdown
Author

Thanks — you're right on the substance. Answering your question directly first: we never looked at the served UI. Our verification notes came from driving the package through start-cli only; we inferred "no provider screen" from upstream rather than from the running 2.4.1 app. We've now inspected it, and it's there:

  • GET /api/integration returns the catalog (334 entries — OpenRouter, Anthropic, OpenAI, LM Studio, …).
  • GET /api/model shows a free default model routed through provider opencode, so the app answers with nothing configured.
  • Settings → Providers is one of the served bundle's own server tabs (providers, models, extensions, projects, workspaces).

So the claim was wrong. Fixed and pushed as 48b957f:

  1. Docs. Restored the audit's step 4 (free hosted model out of the box → your prompts go to OpenCode's servers; hosted providers connect under Settings → Providers) and rewrote the "no provider screen" lines in instructions.md and README.md to say this action is for OpenAI-compatible endpoints the catalog can't reach. The audit's step 4 was correct — we overwrote it.

  2. Reintroductions reverted. Image is pinned "by release tag and manifest-list digest" again; dropped "nothing upstream is disabled or skipped" (the self-updater is off), the warning restatement, and the "(enable an address there …)" parenthetical. AGENTS.md is back to rules: removed the generic "Working here" block and the port and image-pin bullets (the latter duplicates UPDATING.md), and added the scoping rule for this action.

  3. Scoping. The action now owns only the entries it wrote — the opencode.json entries carrying package: @opencode/ai/providers/openai-compatible. It prefills and rebuilds those; every other providers entry is copied through untouched, and model is left alone unless this save sets a Default or it names a managed provider this save removes. That closes all three cases: a hand-added provider is no longer prefilled with a required-empty Base URL, its inline apiKey is no longer deleted, and a model set to something else is no longer cleared. (The built-in opencode provider is not in the config file, so it's untouched either way.)

  4. Comments cut to one fact each in configureProviders.ts, opencode.json.ts, store.json.ts, main.ts, and utils.ts.

npx tsc --noEmit is green. We did not re-run a box test after this revision — you said you'd build and test it, so we left that to you; say the word if you'd rather we exercise it on the 0.4.2 box first. And agreed on order: #2, then rebase #3 onto it, with the CA work reviewed separately.

MattDHill
MattDHill previously approved these changes Nov 25, 2026

@MattDHill MattDHill left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this addresses everything. We tested 48b957f on a StartOS 0.4.3 box (x86_64), installed as an update over the released 2.4.1:0:

  • Update: a session created on 2.4.1:0 survived the update to 2.4.1:1. No task was raised and the service stayed running.
  • Scoping: we hand-wrote an unmanaged provider (no baseURL), a model of opencode/big-pickle, and an unrelated key into opencode.json. The form's prefill left the unmanaged entry out. Saving a managed provider kept all three hand edits, and the API key went only to store.json, referenced as {env:OPENCODE_KEY_ZEN}.
  • Key delivery: the running server carried OPENCODE_KEY_ZEN, and /api/provider listed the provider.
  • Real use: with the action's provider set as Default, a new session ran on it end to end. We pointed it at OpenCode's own OpenAI-compatible endpoint with the key public, and the reply came back from zen/big-pickle.
  • Removal: an empty form removed the managed entry, its key, and the model that named it. The unmanaged entry and the other key stayed, the variable left the server's environment after the restart, and health stayed green with clean logs.

A few small things to pick up when you rebase #3; none blocks this:

  • README § Tasks has gone back to "most plausibly a restore that brought back main without the startos volume". Both volumes are always backed up together, so #1's wording ("It returns only if store.json loses the password") is the accurate one.
  • The provider explanation appears three times in instructions: step 4, the new section, and a Limitations bullet. The same goes for the README's Limitations. It isn't a limitation, so the bullets can go.
  • An ID that collides with an unmanaged entry (say openrouter, hand-added) gets silently turned into a managed one on save. Rejecting an ID that matches an unmanaged entry would prevent that.
  • A hand-written OpenAI-compatible entry with a literal settings.apiKey now counts as managed. Its key prefills blank, so a save deletes it. Prefilling from settings.apiKey when it isn't an {env:…} reference would carry it over into providerKeys.

On #3, once it's rebased on this, the open items are:

  • v2_4_1_1.ts isn't needed (it carries no migration);
  • the CA mount path doesn't need to be keyed by the certificate's hash, since a change read with .const() already restarts the daemon;
  • the README's CA-action section is missing the when/cost/repeat-safety notes;
  • the manifest comment about the CA subtree needs a rewrite.

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 48b957f. Requesting changes for one additional compatibility problem:

P2 — Read OpenCode's supported configuration format (startos/fileModels/opencode.json.ts). The pinned 2.4.1 loader accepts comments and trailing commas in opencode.json, not just in .jsonc files. SDK 4.1.0's FileHelper.json calls JSON.parse. An existing, valid OpenCode configuration containing either therefore prevents the new action's form from opening. The proposal uses the same JSONC parser as upstream through FileHelper.raw, retains unknown fields, and rejects malformed input rather than saving a partial parse.

The proposal also closes the two ownership holes already identified in Matt's review:

  • A submitted ID matching an unmanaged entry overwrites that entry and changes its provider package. Reject that collision inside the config update, before changing either file.
  • A hand-written compatible provider's literal settings.apiKey prefills blank and is deleted on save. Prefill the literal key, including when it supersedes an older stored key, then move it into providerKeys on save.

It includes the previously noted restore-wording and duplicate-limitations cleanup, accurate ownership/JSONC documentation, and trimmed commentary. It leaves #3's CA, alias, and default-selection work alone. Please also update this PR's opening description: it still claims the web app has no provider screen, contrary to the corrected docs and discussion.

The reviewed head merges cleanly with master; all three current CI checks passed. This was a code-only review: I did not build, typecheck, lint, or test the proposal. Please verify a commented/trailing-comma config, an unmanaged-ID collision with neither file changed, and a literal-key round trip when adopting it.

Proposed changes: 48b957f...proposal/2

To adopt the proposal, cherry-pick it onto your branch rather than merging or pulling it, so the PR's head stays your own commit:

git fetch https://github.com/Start9-Community/opencode-startos.git proposal/2
git cherry-pick 48b957fe3b57aeaee30fd12e925aeda792c2561f..FETCH_HEAD

If your branch has moved since 48b957f, resolve any conflicts the cherry-pick reports, or apply the changes your own way. Then push and say so in a comment.

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol

Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
helix-white added a commit that referenced this pull request Nov 25, 2026
Helix-Harness: claude-code
Helix-Model: claude-opus-5-5

@helix-white helix-white left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 3cac22f. It is the earlier proposal as adopted, plus a reworded comment and Prettier's parentheses, and it merges cleanly with master. Nobody has run that proposal yet, so before the verdict I checked it against the pinned sources:

  • JSONC. OpenCode 2.4.1 parses its config with the same call (parse(text, errors, { allowTrailingComma: true })), and it too rejects an empty or malformed file. The README states that saving drops comments.
  • Nested update. SDK 4.1.0 queues file locks per path and rejects only a nested mutation of the same file, so the store.json update inside the opencode.json update takes its own lock. Nothing else writes opencode.json, so the lock order cannot invert. The nested write runs inside the outer callback's 5-second deadline.
  • Bundling. Under ncc, jsonc-parser resolves to its UMD build. I read the bundled javascript/index.js in this run's x86_64 artifact: the wrapper's require parameter is gone and each ./impl/* import is __nccwpck_require__(<id>), so the module loads.

I'm requesting changes for one defect you can reach from the form alone, plus two hand-edit losses in the same code:

  1. Default can't be turned off. When model names a managed provider that stays in the form, un-ticking its Default leaves model unchanged, because the save drops model only when that provider is removed. Reopening the form shows the toggle on again, and new sessions keep starting on that model. The proposal drops model whenever it names a managed entry and no toggle is on. That is the rule from Matt's first review ("touching model only when it names one of them"), and the one AGENTS.md records. OpenCode then falls back to its own choice, as it does out of the box (Model.default() takes the first available text model). A model naming anything else is still left alone. shownModel is now read from the final value.
  2. Any save replaces a hand-set default that isn't the provider's first model. Default always writes the first listed model, but the prefill lists models in file order. So model: "vllm/qwen", with vllm listing glm, qwen, opens with Default on, and an unchanged save (say, while adding another provider) switches the default to vllm/glm. The prefill now lists the current default model first.
  3. A key reference on a hand-written compatible entry is deleted. The prefill blanks any settings.apiKey containing {env: or {file:, so a hand-written "{file:~/.secrets/vllm-key}" is deleted on save and the provider loses its auth. The prefill now blanks only the action's own {env:OPENCODE_KEY_<ID>}, which it still reads back from store.json, and shows anything else as written. On save, an {env:…} or {file:…} key goes back into the entry verbatim and stays out of providerKeys; OpenCode resolves it itself.

The README (What it changes, Repeat safety) and the instructions are updated to match. The proposal adds no strings, so i18n is unchanged.

Please also update the PR description, as asked last round. It still says the web app has no provider screen, and its verification section describes 797e954. This doesn't block the PR, but a squash merge that uses the description would put that text into history.

This was a code-only review: I did not build, typecheck, lint, or run the proposal. I checked new lines against Prettier's 80 columns by hand. When adopting it, please run tsc and Prettier, and exercise:

  • Default on, reopen, turn it off, save: model is dropped and the form reopens with Default off.
  • A hand-set model naming a provider's second model survives an unchanged save.
  • A hand-written compatible entry with "apiKey": "{file:…}" keeps it after a save, and store.json holds no key for it.

Proposed changes: 3cac22f...proposal/2

To adopt the proposal, cherry-pick it onto your branch rather than merging or pulling it, so the PR's head stays your own commit:

git fetch https://github.com/Start9-Community/opencode-startos.git proposal/2
git cherry-pick 3cac22ff1f36e5b109076d11aa36bb9d2a9caf34..FETCH_HEAD

If your branch has moved since 3cac22f, resolve any conflicts the cherry-pick reports, or apply the changes your own way. Then push and say so in a comment.

Helix-Harness: claude-code
Helix-Model: claude-opus-5-5

@jonbotx

jonbotx commented Nov 25, 2026

Copy link
Copy Markdown
Author

Thanks — adopted the proposal.

Cherry-picked proposal/2 onto the branch as 3cac22f (your commit, kept as a cherry-pick rather than a merge), with two small deltas on top: Prettier wanted a clarifying paren in the prefill ternary, and I reworded the prefill comment — it still said the form lists "only the providers this action wrote", but it now also lists hand-written compatible entries.

Verified on a StartOS 0.4.2 box with the CI-built x86_64 package (2.4.1:1), installed over data preserved from the released build, driven through start-cli:

  • JSONC. Seeded opencode.json with comments and trailing commas (plain JSON.parse rejects it) plus one managed and one unmanaged provider. get-input read it and returned the managed entry with its literal key; a save rewrote the file as JSON. The form opens.
  • Collision. Submitting the unmanaged id failed with the new error message, and both opencode.json and store.json were byte-for-byte unchanged.
  • Literal key. A hand-written compatible entry with a literal settings.apiKey prefilled that key; saving wrote {env:OPENCODE_KEY_LAB} to the config, moved the literal into store.json → providerKeys, left the unmanaged entry and the model of opencode/big-pickle untouched, and the daemon came back carrying OPENCODE_KEY_LAB.

tsc --noEmit and Prettier pass, and CI builds both arches. I've also rewritten the PR description — it no longer claims the app has no provider screen.

@MattDHill — your four small items (README § Tasks wording, the repeated provider explanation, the ID collision, the literal key) are all in the proposal and verified above. Your #3 list — drop v2_4_1_1.ts, drop the cert-hash keying (the .const() read already restarts), the README when/cost/repeat-safety notes, and the manifest comment rewrite — I'll pick up when I rebase #3 once this lands.

@MattDHill MattDHill left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 3cac22f. We ran the same three cases on our box (a commented config with trailing commas, the ID collision with neither file changed, the literal-key round trip with a prompt through that provider), and both arches built in CI. Thanks for turning these rounds around so quickly.

@MattDHill
MattDHill dismissed helix-white’s stale review November 25, 2026 17:25

Merging #2 as is. Start9 is taking this review's three fixes (proposal/2) in its own follow-up PR, so nothing more is needed from the submitter here.

@MattDHill
MattDHill merged commit 05ce509 into Start9-Community:master Nov 25, 2026
3 checks passed
@MattDHill

Copy link
Copy Markdown
Member

Merged — thank you, and sorry for the number of rounds. Each time you did exactly what we asked, and each review turned up something we should have caught the round before. That's on our side, not yours.

helix-white's last review found three more edge cases:

  • unticking Default doesn't clear the default model;
  • an unchanged save can replace a hand-set default with the provider's first model;
  • a hand-written {file:…} or {env:…} key reference gets blanked.

Two were already in the code we approved, and the third came from our own proposal. We're fixing all three ourselves in a follow-up PR against master, so there's nothing more for you to do here.

For #3, rebase onto master once our follow-up lands. We'll keep that review light and handle small fixes on our side rather than send you round after round.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants